package com.example.apipassenger.service;

import com.example.apipassenger.remote.ServicePriceClient;
import com.example.internalcommon.dto.ResponseResult;
import com.example.internalcommon.request.ForecastPriceDTO;
import com.example.internalcommon.response.ForecastPriceResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author lyra
 * @Date 2023/4/9 10:55
 **/
@Service
@Slf4j
public class ForecastPriceService {

    @Autowired
    ServicePriceClient servicePriceClient;

    /**
     * 11. 根据 出发和目的地经纬度 计算预估价格
     *
     * @param depLongitude
     * @param depLatitude
     * @param destLongitude
     * @param destLatitude
     * @return
     */
    public ResponseResult forecastPrice(String depLongitude, String depLatitude, String destLongitude, String destLatitude,
                                        String cityCode, String vehicleType) {

        log.info("出发地的经度" + depLongitude);
        log.info("出发地的维度" + depLatitude);
        log.info("目的地的经度" + destLongitude);
        log.info("目的地的经度" + destLatitude);

        log.info("调用计价服务,计算价格");
        ForecastPriceDTO forecastPriceDTO = new ForecastPriceDTO();
        forecastPriceDTO.setDepLongitude(depLongitude);
        forecastPriceDTO.setDepLatitude(depLatitude);
        forecastPriceDTO.setDestLongitude(destLongitude);
        forecastPriceDTO.setDestLatitude(destLatitude);
        forecastPriceDTO.setCityCode(cityCode);
        forecastPriceDTO.setVehicleType(vehicleType);

        ResponseResult<ForecastPriceResponse> forecast = servicePriceClient.forecast(forecastPriceDTO);
        // ForecastPriceResponse data = forecast.getData();
        // double price = data.getPrice();
        // String fareType = data.getFareType();
        //
        //
        // ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse();
        // forecastPriceResponse.setPrice(price);
        // forecastPriceResponse.setCityCode(cityCode);
        // forecastPriceResponse.setVehicleType(vehicleType);

        // return ResponseResult.success(forecastPriceResponse);
        return ResponseResult.success(forecast.getData());
    }

}
